package com.zhongmeng.rxjava2test.modle


import com.zhongmeng.rxjava2test.base.BaseModle
import com.zhongmeng.rxjava2test.utils.DisposableUtils

import io.reactivex.Observable
import io.reactivex.disposables.Disposable

/**
 * author :rcw.
 * date :2017/10/12 11:12.
 */

class HomeModleImpl(private val onRequestListener: BaseModle.OnRequestListener<*>) : BaseModle {

    /*@Override
    public <T> Disposable getObservable(Observable<T> observable, final int which) {
        Disposable disposable=observable
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<T>() {
                    @Override
                    public void accept(T data) throws Exception {
                        if (onRequestListener!=null){
                            onRequestListener.onRequestSuccess(data,which);
                        }
                    }

                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        if (onRequestListener!=null){
                            onRequestListener.onRequestFail(throwable);
                        }
                    }
                });
        return disposable;
    }*/

    override fun <T> getObservable(observable: Observable<T>, which: Int): Disposable {
        return DisposableUtils.getDisposable<T>(observable, which, onRequestListener as BaseModle.OnRequestListener<T>)
    }
}
